//
//  NSDate+Util.m
//  MobileCRM
//
//  Created by winter on 16/2/22.
//  Copyright © 2016年 江苏金恒信息科技有限公司. All rights reserved.
//

#import "NSDate+Util.h"


@implementation NSDate(Util)

- (NSString *)convertToStringWithFormat:(NSString *)formatStr
{
    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    [format setDateFormat:formatStr];
    return [format stringFromDate:self];
}

- (NSDateComponents *)wsCalcDate
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSUInteger flags = NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit;
    NSDateComponents *compontents = [calendar components:flags fromDate:self];
    return compontents;
#pragma clang diagnostic pop
}

+ (NSDateComponents *)wsCalcOffsetBetween:(NSDate *)dt1 dt2:(NSDate *)dt2
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSUInteger flags = NSHourCalendarUnit|NSDayCalendarUnit;
    NSDateComponents *com = [calendar components:flags fromDate:dt1 toDate:dt2 options:0];
    return com;
#pragma clang diagnostic pop
}

@end
